package app

import (
	"api-go/model"
	"api-go/serializer"

	"github.com/gin-gonic/gin"
)

//获取更新所需信息
type AppUpdateService struct {
	Type    int `form:"type"`
	Version int `form:"version"`
}

// 返回更新信息
func (service *AppUpdateService) AppUp() *serializer.Response {
	var app model.AppUpdate

	if err := model.DB.Where("type = ? and version_code > ?", service.Type, service.Version).Order("id DESC").First(&app).Error; err != nil {
		return serializer.OkResponse(nil)
	}

	data := gin.H{
		"versionCode": app.VersionCode,
		"versionName": app.VersionName,
		"versionInfo": app.VersionInfo,
		"updateType":  app.UpdateType,
		"downloadUrl": app.DownloadUrl,
	}
	return serializer.OkResponse(&data)
}
